package com.sun.androidexerciseproject.function.pattern;

import android.support.annotation.Nullable;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2018/2/22 0022.
 */

public class PatternTest {
    public static void main(String[] args) {
        Pattern pattern = Pattern.compile("\\w+");
        String regex = pattern.pattern();
        System.out.println("regex = " + regex);
        pattern = Pattern.compile("\\d+");
        String[] str = pattern.split("我的Q:2233 我的电话是:323434 my email is:33424@qq.com");
        for (String temp : str) {
            System.out.println("str = " + temp);
        }
        pattern = Pattern.compile("[1-9a-zA-Z]?");
        Matcher matcher = pattern.matcher("sj");
        boolean ret = matcher.matches();
        System.out.println("ret = " + ret);
        pattern = Pattern.compile("^123");
        System.out.println("ret1 = " + pattern.matcher("123").matches());
        System.out.println("ret2 = " + pattern.matcher("2343123").matches());
        pattern = Pattern.compile("123$");
        System.out.println("ret3 = " + pattern.matcher("123888").matches());
        System.out.println("ret4 = " + pattern.matcher("123").matches());
        pattern = Pattern.compile("o{2}");
        System.out.println("ret5 = " + pattern.matcher("food").lookingAt());
        System.out.println("ret6 = " + pattern.matcher("fod").matches());
        nullTest("test");
        String a = null;
        nullTest(a);
        regex = "^[0-9]+()abc$";
        pattern = Pattern.compile(regex);
        ret = pattern.matcher("1234556$#@abc").matches();
        System.out.println("ret7 = " + ret);
        ret = pattern.matcher("123abc").matches();
        System.out.println("ret8 = " + ret);
        ret = pattern.matcher("abc").matches();
        System.out.println("ret9 = " + ret);
        System.out.println("1123213|");
        String temp = Integer.toString(1024, 2);
        System.out.println(String.format("temp is %s", temp));
        int value = Integer.parseInt(temp, 2);
        System.out.println(String.format("value is %d", value));
        temp = "1024Weixin";
        ret = temp.startsWith("Weixin", 4);
        System.out.println(String.format("ret is %b", ret));
        ret = temp.startsWith("Weixin", 3);
        System.out.println(String.format("ret is %b", ret));
        ret = temp.equalsIgnoreCase("1024weixin");
        System.out.println(String.format("ret is %b", ret));
        ret = "123456545fsrabc".matches(regex);
        System.out.println(String.format("match ret is %b", ret));
        temp = "zo";
        ret = temp.matches("zo*");
        System.out.println(String.format("match ret is %b", ret));

        Scanner scanner = new Scanner(System.in);
        System.out.println("What is your name");
        temp = scanner.nextLine();
        System.out.println(String.format("temp is %s", temp));
        temp = scanner.next();
        System.out.println(String.format("temp is %s", temp));
    }

    private static @Nullable
    String nullTest(String input) {
        System.out.println(input);
        System.out.println("end");
        return input;
    }
}
